﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SILAS.BL;
using SILAS.Entidades;
using Microsoft.Practices.Unity;
using SILAS.UI.Models;
namespace SILAS.UI.Controllers
{
    public class CapacitacionController : Controller
    {
        //
        [Dependency]
        public ICapacitacionBL capacitacionBL { get; set; }

        [Dependency]
        public IJassBL jassBL { get; set; }

        // GET: /Capacitacion/

        public ActionResult Index(int id)
        {
            var idjass = id;
            ViewBag.id = idjass;
            var listi = capacitacionBL.ListarCapacitacionByIdJass(idjass);

            return View(listi);
        }

        public ActionResult ListaCapacitaciones(string criterio)
        {

            var lista = capacitacionBL.GetAllFromEmpleadoByCapacitacion(criterio);
            return View(lista);
        }
        // GET: /Capacitacion/Details/5

        public ActionResult Details(int id)
        {
            var capa = capacitacionBL.getCapacitacionbyId(id);
            return View(capa);
        }

        //
        // GET: /Capacitacion/Create

        public ActionResult Create(int id)
        {
            ViewBag.idjass = id;
            return View();

        }

        //
        // POST: /Capacitacion/Create

        [HttpPost]
        public ActionResult Create(Capacitacion capacitacion, FormCollection _form)
        {
            try
            {
                capacitacionBL.agregarCapacitacion(capacitacion);


                var result = new
                {
                    msg = "Capacitacion creada exitosamente",
                    exito = true
                };

                return Json(result, JsonRequestBehavior.AllowGet);
            }
            catch (SystemException ex)
            {
                var result = new
                {
                    msg = ex.Message,
                    exito = false
                };

                return Json(result, JsonRequestBehavior.AllowGet);

            }
        }

        //
        // GET: /Capacitacion/Edit/5

        public ActionResult Edit(int id)
        {
            var capa = capacitacionBL.getCapacitacionbyId(id);
            return View(capa);
        }

        //
        // POST: /Capacitacion/Edit/5

        [HttpPost]
        public ActionResult Edit(Capacitacion capacitacion, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
                capacitacionBL.modificarCapacitacion(capacitacion);

                var result = new
                {
                    msg = "La Información fue Guardada Correctamente",
                    exito = true
                };

                return Json(result, JsonRequestBehavior.AllowGet);

            }
            catch (SystemException ex)
            {

                var result = new
                {
                    msg = ex.Message,
                    exito = false
                };

                return Json(result, JsonRequestBehavior.AllowGet);
            }
        }

        //
        // GET: /Capacitacion/Delete/5

        public ActionResult Delete(int id)
        {
            capacitacionBL.eliminarCapacitacion(id);
            return RedirectToAction("ListaCapacitaciones");
        }

        //
        // POST: /Capacitacion/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}